package com.mitchellbosecke.benchmark;

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Setup;
import top.jfunc.cron.util.CronSequenceGenerator;
import top.jfunc.cron.util.CronUtil;
import top.jfunc.cron.util.DateUtil;

import java.io.IOException;
import java.util.Date;

public class CronHmsBenchmark extends BaseBenchmark {
    @Setup
    public void setup() throws IOException {
    }

    @Benchmark
    public Date cronHms0(){
        Date date = DateUtil.toDate("2018-11-23 18:50:00");
        String cron = "0 30 2 ? * WED";
        return CronUtil.next(cron, date);
    }
    @Benchmark
    public Date cronHms1(){
        Date date = DateUtil.toDate("2018-11-18 12:00:12");
        String cron = "2 15 12 ? * *";
        return CronUtil.next(cron, date);
    }
    @Benchmark
    public Date cronHms2(){
        Date date = DateUtil.toDate("2011-03-25 13:22:43");
        String cron = "0 0 8 * * *";
        return CronUtil.next(cron, date);
    }
    @Benchmark
    public Date cronHms3(){
        Date date = DateUtil.toDate("2016-12-25 18:00:45");
        String cron = "0/2 1 * * * *";
        return CronUtil.next(cron, date);
    }
    @Benchmark
    public Date cronHms4(){
        Date date = DateUtil.toDate("2016-01-29 04:01:12");
        String cron = "0 0/5 14,18 * * ?";
        return CronUtil.next(cron, date);
    }
    @Benchmark
    public Date cronHms5(){
        Date date = DateUtil.toDate("2022-08-31 23:59:59");
        String cron = "0 15 10 ? * MON-FRI";
        return CronUtil.next(cron, date);
    }
    @Benchmark
    public Date cronHms6(){
        Date date = DateUtil.toDate("2013-09-12 03:04:05");
        String cron = "0 26,29,33 * * * ?";
        return CronUtil.next(cron, date);
    }
    @Benchmark
    public Date cronHms7(){
        Date date = DateUtil.toDate("1999-10-18 12:00:00");
        String cron = "10-20/4 10,44,30/2 10 ? 3 WED";
        CronUtil.next(cron, date);
        CronUtil.next(cron, date);
        return CronUtil.next(cron, date);
    }
    @Benchmark
    public Date cronHms8(){
        Date date = DateUtil.toDate("2008-09-11 19:19:19");
        String cron = "0 0 0 1/2 MAR-AUG ?";
        return CronUtil.next(cron, date);
    }
    @Benchmark
    public Date cronHms9(){
        Date date = DateUtil.toDate("2003-02-09 06:17:19");
        String cron = "0 10-20/3,57-59 * * * WED-FRI";
        return CronUtil.next(cron, date);
    }
    @Benchmark
    public Date cronHms10(){
        Date date = DateUtil.toDate("2016-12-28 19:01:35");
        String cron = "0 10,44 14 ? 3 WED";
        return CronUtil.next(cron, date);
    }

    @Benchmark
    public Date cronHms11(){
        Date date = DateUtil.toDate("2018-11-18 12:00:12");
        String cron = "0-12/12 00 12 ? * *";
        return CronUtil.next(cron, date);
    }

    /**
     * 以下是一些极端情况，属于撞大运的
     */
    @Benchmark
    public Date cronHms12(){
        Date date = DateUtil.toDate("2018-11-18 12:00:12");
        String cron = "2 15 23 3 3 7";
        Date next = new CronSequenceGenerator(cron).next(date);
        return CronUtil.next(cron, date);
    }
    @Benchmark
    public Date cronHms13(){
        Date date = DateUtil.toDate("2018-11-18 12:00:12");
        String cron = "2 15 23 3 3 6";

        return CronUtil.next(cron, date);
    }
    @Benchmark
    public Date cronHms14(){
        Date date = DateUtil.toDate("2018-11-18 12:00:12");
        String cron = "2 15 23 3 3 5";

        return CronUtil.next(cron, date);
    }
    @Benchmark
    public Date cronHms15(){
        Date date = DateUtil.toDate("2018-11-18 12:00:12");
        String cron = "2 15 23 3 3 4";

        return CronUtil.next(cron, date);
    }
    @Benchmark
    public Date cronHms16(){
        Date date = DateUtil.toDate("2018-11-18 12:00:12");
        String cron = "2 15 23 3 3 3";

        return CronUtil.next(cron, date);
    }
    @Benchmark
    public Date cronHms17(){
        Date date = DateUtil.toDate("2018-11-18 12:00:12");
        String cron = "2 15 23 3 3 2";

        return CronUtil.next(cron, date);
    }
}




